#ifndef __ALTAIR_STRING_GETPASS_H__
#define __ALTAIR_STRING_GETPASS_H__

#include <stdio/getchar.h>
#include <stdio/putchar.h>

/**
 *  getpass()
 *  sejme string z klavesnice o maximalni delce <size>, kazdy znak nahradi
 *  znakem <passchr>
 */
char *getpass(char *cs, int size, char passchr) {
  unsigned int counter = 0;
  unsigned char c = '\0';
  char *s;

  s = cs;
  while (1) {
    if(counter >= size)
      break;
    c = getchar();
    if(c == '\r') break;
    if(c == '\n') break;
    if(c == '\0') break;

      if(!(counter == 0 && c == '\b'))
        if(c == '\b')
          putchar('\b');
        else
          putchar(passchr);

      if(c == '\b') {
        if (counter > 0)
        counter--;
      } else
        *(s+(counter++)) = c;
  }
  putchar('\n');
  *(s+(counter++)) = '\0';
  return s;
}

#endif
